package testcase.command;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.NoSuchElementException;

import org.junit.Test;

import satir.card.Choice;
import satir.card.Question;
import satir.command.AskQuestionCmd;
import satir.player.Player;
import junit.framework.TestCase;


public class AskQuestionCmd_askQuestion_1 extends TestCase{
	
	public static class AskQuestionCmdStub extends AskQuestionCmd {
		public AskQuestionCmdStub(Question question, Player player) {
			super(question, player);
		}	
		public void doAskQuestion(ArrayList<Choice> choices){
			this.askQuestion(choices);
		}
	};
	private AskQuestionCmdStub askQuestionCmdStub;
	ArrayList<Choice> choices;
		
	/**
	 * Sets up the test fixture. Called before every test case method.
	 */
	public void setUp() {
		choices = new ArrayList<Choice>();
		// give choice
		choices.add(new Choice(
				"Blame him/her and prohibit use the phone more than 5 mins.",
				1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Talk with son/daughter and find the reason.",
				1, new Hashtable<String, Integer>()));
		choices.add(new Choice(
				"Threaten son/daughter. If the situation still not change, you will modify the amount of pocket money.",
				-1, new Hashtable<String, Integer>()));
		choices.add(new Choice("Ignore him/her.", -1,
				new Hashtable<String, Integer>()));
		// give a question
		String question1 = "Mother notices her children talk with classmate at night about 30 mins or more. As Father, what is your decision?";
		Player player = new Player();
		Question question = new Question(question1, choices);

		// create questions array
		ArrayList<Question> questions = new ArrayList<Question>();
		questions.add(question);

		askQuestionCmdStub = new AskQuestionCmdStub(question, player);
	}
	/**
	 * Tears down the test fixture. Called after every test case method.
	 */
	public void tearDown() {
	}
	
	/*
	 * Step :1
	 * Test whether it can print a re-Answer request 
	 */
	@Test 
	public void testReAnswerRequest(){
		
		final ByteArrayOutputStream systemOut = new ByteArrayOutputStream();
		PrintStream original = System.out;
		System.setOut(new PrintStream(systemOut)); // Start store the output here
		try {
			askQuestionCmdStub.doAskQuestion(choices);
		} catch (NoSuchElementException e) {
		}
		
		System.setOut(original); // Store the output unit here
		String actualResult = systemOut.toString();
		String expectedResult = ("Please indicate your selection:  [1] Blame him/her and prohibit use the phone more than 5 mins.\r\n" +
				", [2] Talk with son/daughter and find the reason.\r\n" +
				", [3] Threaten son/daughter. If the situation still not change, you will modify the amount of pocket money.\r\n" +
				", [4] Ignore him/her.\r\n" +
				"\n");
		assertEquals(actualResult,expectedResult);
	}
	
}
